﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:System.Controls">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Common.xaml" />
  </ResourceDictionary.MergedDictionaries>


  <ControlTemplate x:Key="controlTemplate" TargetType="{x:Type local:TextBox}">

    <Grid>

      <Grid.ColumnDefinitions>
        <ColumnDefinition x:Name="left_col" Width="Auto" SharedSizeGroup="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SharedSizeGroup}"/>
        <ColumnDefinition />
        <ColumnDefinition x:Name="right_col" Width="Auto"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition x:Name="top_row" Height="Auto"/>
        <RowDefinition />
        <RowDefinition x:Name="bottom_row" Height="Auto"/>
      </Grid.RowDefinitions>

      <local:TextLabel
        x:Name="label"
        Grid.Column="0"
        Grid.Row="1"
        Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=HasContent, Converter={StaticResource b2v}}"
        Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"/>

      <Border 
        Grid.Column="1"
        Grid.Row="1"
        
        x:Name="PART_border"
        CornerRadius="{TemplateBinding CornerRadius}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        BorderBrush="{TemplateBinding BorderBrush}" 
      
        Background="{TemplateBinding Background}" 
        OpacityMask="{TemplateBinding OpacityMask}" 
      
        MinWidth="{TemplateBinding MinWidth}" 
        MinHeight="{TemplateBinding MinHeight}" 
        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
        <ScrollViewer 
          x:Name="PART_ContentHost" 
          HorizontalScrollBarVisibility="Disabled" 
          VerticalScrollBarVisibility="Disabled" 
          FontFamily="{TemplateBinding FontFamily}" 
          FontSize="{TemplateBinding FontSize}" 
          FontWeight="{TemplateBinding FontWeight}" 
          Foreground="{TemplateBinding Foreground}" 
          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
          HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
          Padding="{TemplateBinding Padding}" />
      </Border>

    </Grid>

    <ControlTemplate.Triggers>
      <Trigger Property="ContentDock" Value="Top">
        <Setter Property="Grid.Column" Value="1" TargetName="label"/>
        <Setter Property="Grid.Row" Value="0" TargetName="label"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="left_col"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="right_col"/>
      </Trigger>

      <Trigger Property="ContentDock" Value="Bottom">
        <Setter Property="Grid.Column" Value="1" TargetName="label"/>
        <Setter Property="Grid.Row" Value="2" TargetName="label"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="left_col"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="right_col"/>
      </Trigger>

      <Trigger Property="ContentDock" Value="Right">
        <Setter Property="Grid.Column" Value="2" TargetName="label"/>
        <Setter Property="Grid.Row" Value="1" TargetName="label"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="left_col"/>
        <Setter Property="SharedSizeGroup" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SharedSizeGroup}" TargetName="right_col"/>
      </Trigger>

    </ControlTemplate.Triggers>

  </ControlTemplate>

  <Style x:Key="TextBoxBaseStyle" TargetType="{x:Type local:TextBox}"  BasedOn="{StaticResource {x:Type Control}}">

    <Setter Property="CornerRadius" Value="2" />
    <Setter Property="Padding" Value="3"/>

    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="BorderBrush" Value="DodgerBlue"/>

    <Setter Property="Foreground" Value="{StaticResource TextBoxForegroundBrush}" />
    <Setter Property="Background" Value="{StaticResource TextBoxBackgroundBrush}" />

    <Setter Property="Template" Value="{StaticResource controlTemplate}" />

    <Style.Triggers>
      <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Opacity" Value="0.75"/>
      </Trigger>

      <Trigger Property="IsFocused" Value="true">
        <Setter Property="Background" Value="{StaticResource TextBoxActiveBackGound}" />
      </Trigger>

    </Style.Triggers>

  </Style>

  <Style TargetType="{x:Type local:TextBox}" BasedOn="{StaticResource TextBoxBaseStyle}">
    <Setter Property="VerticalContentAlignment" Value="Center"/>
  </Style>

  <Style TargetType="{x:Type local:MemoEdit}" BasedOn="{StaticResource TextBoxBaseStyle}">
    <Setter Property="AcceptsReturn" Value="True"/>
    <Setter Property="AcceptsTab" Value="True"/>
    <Setter Property="AutoWordSelection" Value="True"/>
    <Setter Property="TextWrapping" Value="Wrap"/>
    <Setter Property="Height" Value="Auto"/>
    <Setter Property="MaxLines" Value="1024"/>
    <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="TextAlignment" Value="Justify"/>
  </Style>

</ResourceDictionary>